<?php

namespace app\api\controller;
use app\Request;
use think\facade\Db;

//爬虫
class Whale
{

//weixian_yayun 19 21
//chache
//weixian_zhuangxie
    //参数设置
    public $type="weixian_zhuangxie"; //
    public $km="zigezheng"; //
    public $km1="zigezheng";
    public $type1="zigezheng"; //
    public $type11="_21_"; //

    public function test()
    {
        $list=Db::table("zl_questions_content")
            ->where("id","<=",10000000)
            ->update(["ext1"=>""]);

//        $list=Db::table("zl_questions_content")
//            ->where("label","k4")
//            ->where("cate",$this->type11)
//            ->update(["label"=>"zigezheng"]);
//        dump(Db::table("zl_questions_content")->getLastSql());
    }

    public function chapter()
    {
        $carStyle=[
            "_7_"=>"xiaoche",
            "_8_"=>"keche",
            "_9_"=>"huoche",
            "_10_"=>"moto",
            "_12_"=>"keyun",
            "_13_"=>"huoyun",
            "_14_"=>"weixian",
            "_15_"=>"jiaolian",
            "_16_"=>"chuzu",
            "_17_"=>"light_trailer",
            "_18_"=>"wangyue",
            "_20_"=>"chache",
            "_19_"=>"weixian_yayun",
            "_21_"=>"weixian_zhuangxie",
        ];

        $carType=[
            "_7_"=>"car",
            "_8_"=>"bus",
            "_9_"=>"truck",
            "_10_"=>"moto",
            "_12_"=>"keyun",
            "_13_"=>"huoyun",
            "_14_"=>"weixian",
            "_15_"=>"jiaolian",
            "_16_"=>"chuzu",
            "_17_"=>"light_trailer",
            "_18_"=>"wangyue",
            "_20_"=>"chache",
            "_19_"=>"weixian_yayun",
            "_21_"=>"weixian_zhuangxie",
        ];



        $cate=[
            "k1"=>"kemu1",
            "k4"=>"kemu3",
            "zigezheng"=>"zigezheng",
        ];

        $cate1=[
            "k1"=>"kemu1",
            "k4"=>"kemu4",
            "zigezheng"=>"zigezheng",
        ];


        $chapters=Db::table("zl_questions_chapter")
            ->where("sort","0")
            ->select();

        foreach ($chapters as $chapter)
        {
            $sign=$this->getRequest("http://sv.daimapuzi.com/api/whale/sign1");
            $url="https://api2.jiakaobaodian.com/api/open/exercise/chapter.htm?_r=".$sign."&carStyle=".$carStyle[$chapter["cate"]]."&carType=".$carType[$chapter["cate"]]."&course=".$cate[$chapter["label"]]."&kemuStyle=".$cate1[$chapter["label"]]."&tagId=".$chapter["source_id"]."&chapterId=".$chapter["source_id"];
//            var_dump($url);exit;
            $return = json_decode($this->getRequest($url),1);
            Db::table("zl_questions_chapter")->where("id",$chapter["id"])->update(["ids"=>json_encode($return["data"]["questionList"])]);
        }



    }

    public function chapterUpdate()
    {
        $chapters=Db::table("zl_questions_chapter")
            ->where("cate","_21_")
            ->select();

        foreach ($chapters as $chapter)
        {
            $where=json_decode($chapter["ids"]);
            $ids=Db::table("zl_questions_content")
                ->field("id")
                ->where("cate",$chapter["cate"])
                ->where("source_id","in",implode(",",$where))->select()->toArray();
            $ids=array_column($ids,"id");

            Db::table("zl_questions_chapter")->where("id",$chapter["id"])->update(["ids"=>json_encode($ids)]);
        }



    }

    public function labels()
    {
        $carStyle=[
            "_7_"=>"xiaoche",
            "_8_"=>"keche",
            "_9_"=>"huoche",
            "_10_"=>"moto",
            "_12_"=>"keyun",
            "_13_"=>"huoyun",
            "_14_"=>"weixian",
            "_15_"=>"jiaolian",
            "_16_"=>"chuzu",
        ];

        $carType=[
            "_7_"=>"car",
            "_8_"=>"bus",
            "_9_"=>"truck",
            "_10_"=>"moto",
            "_12_"=>"keyun",
            "_13_"=>"huoyun",
            "_14_"=>"weixian",
            "_15_"=>"jiaolian",
            "_16_"=>"chuzu",
        ];



        $cate=[
            "k1"=>"kemu1",
            "k4"=>"kemu3",
            "zigezheng"=>"zigezheng",
        ];

        $cate1=[
            "k1"=>"kemu1",
            "k4"=>"kemu4",
            "zigezheng"=>"zigezheng",
        ];


        $labels=Db::table("zl_questions_label")
            ->select();

        foreach ($labels as $label)
        {
            $sign=$this->getRequest("http://sv.daimapuzi.com/api/whale/sign1");
            $url="https://api2.jiakaobaodian.com/api/open/question/list-by-tag.htm?_r=".$sign."&carStyle=".$carStyle[$label["cate"]]."&carType=".$carType[$label["cate"]]."&course=".$cate[$label["label"]]."&kemuStyle=".$cate1[$label["label"]]."&tagId=".$label["source_id"];
//            var_dump($url);exit;
            $return = json_decode($this->getRequest($url),1);
//            dd($return);
            Db::table("zl_questions_label")->where("id",$label["id"])->update(["ids"=>json_encode($return["data"])]);
        }


    }

    public function labelsUpdate()
    {
        $labels=Db::table("zl_questions_label")
            ->select();

        foreach ($labels as $label)
        {
            $where=json_decode($label["ids"]);
            $ids=Db::table("zl_questions_content")
                ->field("id")
                ->where("cate",$label["cate"])
                ->where("source_id","in",implode(",",$where))->select()->toArray();
            $ids=array_column($ids,"id");

            Db::table("zl_questions_label")->where("id",$label["id"])->update(["ids"=>json_encode($ids)]);
        }



    }

    //列表
    public function ids()
    {
        //获取科目数据
        $ids=json_decode($this->keMu($this->type,$this->type1,$this->km),1);
        //组装入库
        $data=[];
        foreach ($ids["data"] as $id)
        {
            $data[]=[
                "source_id"=>$id,
                "cate"=>$this->type11,
                "label"=>$this->km1,
                "source"=>"jkbd",
            ];
        }
        Db::table("zl_questions_content")->insertAll($data);
        var_dump($data);
    }


    public function keMu($type,$type1,$km)
    {
//        $url="https://api2.jiakaobaodian.com/api/open/exercise/sequence.htm?carType=light_trailer&course=kemu3&cityCode=654300&tagId=undefined&chapterId=undefined&knowledgeIds=undefined&_r=11550864197736106085&authToken=undefined&_language=zh_CN&_windowHeight=782&_screenWidth=414&_screenHeight=896&_osType=mac&_platform=mac&_product=%E9%A9%BE%E8%80%83%E5%AE%9D%E5%85%B8%E5%B0%8F%E7%A8%8B%E5%BA%8F&_appName=jiakao_miniprogram&_pkgName=jiakaobaodianxiaochengxu.applet&_screenDpi=1&_manufacturer=Macmini9%2C1&_version=7.0.8&_deviceId=oK1QY0RnhtlDODESCnVbd0_Uv9ic";
//        var_dump($url);
        $sign=$this->getRequest("http://sv.daimapuzi.com/api/whale/sign1");
        $url="https://api2.jiakaobaodian.com/api/open/exercise/sequence.htm?_r=".$sign."&carStyle=".$type1."&carType=".$type."&course=".$km."&kemuStyle=".$km;
//        var_dump($url);exit;
        $return = $this->getRequest($url);
        return $return;
    }

    //详情
    public function detail()
    {

        set_time_limit(0);
        $list=Db::table("zl_questions_content")
            ->where("label",$this->km1)
            ->where("cate",$this->type11)
            ->order("id","desc")
            ->select();

        $optionType=[
            0=>20,
            1=>10,
            2=>10
        ];

        $optionTypeC=[
            0=>10,
            1=>10,
            2=>20
        ];
        foreach ($list as $item)
        {
            $id=$item["source_id"];
            $content=json_decode($this->view($this->type,$id),1);
            $question=[
                "question"=>$content["data"]["question"],
                "key_words"=>$content["data"]["assuredKeywords"],
                "answer"=>$content["data"]["answer"],
                "media_url"=>$content["data"]["mediaContent"],
                "media_type"=>$content["data"]["mediaType"]."0",
                "item1"=>$content["data"]["optionA"],
                "item2"=>$content["data"]["optionB"],
                "item3"=>$content["data"]["optionC"],
                "item4"=>$content["data"]["optionD"],
                "item5"=>$content["data"]["optionE"],
                "item6"=>$content["data"]["optionF"],
                "item7"=>$content["data"]["optionG"],
                "item8"=>$content["data"]["optionH"],
                "concise_explains"=>$content["data"]["conciseExplain"],
                "difficulty"=>$content["data"]["difficulty"],
                "wrong_rate"=>$content["data"]["wrongRate"],
                "ext"=>$content["data"]["label"], //标签
//                "ext1"=>$content["data"]["chapterId"], //专题
                "explains"=>$content["data"]["explain"],
                "illiteracy_explain"=>$content["data"]["illiteracyExplain"],
                "illiteracy_keywords"=>$content["data"]["illiteracyKeywords"],
                "type"=>$optionType[$content["data"]["optionType"]],
                "type_c"=>$optionTypeC[$content["data"]["optionType"]],
            ];
            Db::table("zl_questions_content")->where("source_id",$id)->update($question);
        }



        return 1;

    }

    public function view($type,$id)
    {
        $sign=$this->getRequest("http://sv.daimapuzi.com/api/whale/sign1");
        $url="https://api2.jiakaobaodian.com/api/open/question/view.htm?_r=".$sign."&carType=".$type."&questionId=".$id;
//        var_dump($url);
//        exit;
        $return = $this->getRequest($url);
        return $return;
    }

    //标签（知识类型）
    public function label()
    {
        $sign=$this->getRequest("http://sv.daimapuzi.com/api/whale/sign1");
        $url="https://api2.jiakaobaodian.com/api/open/exercise/strengthen.htm?_r=".$sign."&carType=".$this->type."&course=".$this->km;
        $return = $this->getRequest($url);
        var_dump($return);
        $content=json_decode($return,1);
        $data=[];
        foreach ($content["data"]["nodes"] as $node)
        {
            if($node["label"] == "按知识点类型")
            {
                foreach ($node["nodes"] as $n)
                {
                    $data[]=[
                        "source_id"=>$n["tagId"],
                        "name"=>$n["label"],
                        "cate"=>$this->type11,
                        "label"=>$this->km1,
                    ];
                }
            }
        }
        Db::table("zl_questions_label")->insertAll($data);
    }

    public function labelGx()
    {
        $list=Db::table("zl_questions_label")
            ->where("label",$this->km1)
            ->where("cate",$this->type11)
            ->select();
        foreach ($list as $item)
        {
//            var_dump($item);
            $ids=$this->labelContent($item["source_id"]);
//            var_dump($ids);
            Db::table("zl_questions_content")
                ->where("source_id","in",$ids)
                ->update(["label1"=>$item["id"]]);
//            exit;
        }

    }

    public function labelContent($label)
    {
        $sign=$this->getRequest("http://sv.daimapuzi.com/api/whale/sign1");
        $url="https://api2.jiakaobaodian.com/api/open/question/list-by-tag.htm?_r=".$sign."&carStyle=".$this->type1."&carType=".$this->type."&course=".$this->km."&tagId=".$label;
        $return = $this->getRequest($url);
        $content=json_decode($return,1);
        return implode(",",$content["data"]);
    }

    public function labelNew()
    {
        //新规题
        $ids=$this->labelContent(146);
        Db::table("zl_questions_content")
            ->where("source_id","in",$ids)
            ->update(["label2"=>1]);
    }


    //地方题库
    public function difang()
    {
        $json='{  
  "provinces": [  
  {  
      "name": "四川省",  
      "capital": "成都市",  
      "adminCode": "510100"  
    }, 
    {  
      "name": "北京市",  
      "capital": "北京市",  
      "adminCode": "110000"  
    },  
    {  
      "name": "河北省",  
      "capital": "石家庄市",  
      "adminCode": "130100"  
    },  
    {  
      "name": "山西省",  
      "capital": "太原市",  
      "adminCode": "140100"  
    },  
    {  
      "name": "辽宁省",  
      "capital": "沈阳市",  
      "adminCode": "210100"  
    },  
    {  
      "name": "江苏省",  
      "capital": "南京市",  
      "adminCode": "320100"  
    },  
    {  
      "name": "浙江省",  
      "capital": "杭州市",  
      "adminCode": "330100"  
    },  
    {  
      "name": "福建省",  
      "capital": "福州市",  
      "adminCode": "350100"  
    },  
    {  
      "name": "广东省",  
      "capital": "广州市",  
      "adminCode": "440100"  
    },   
    {  
      "name": "陕西省",  
      "capital": "西安市",  
      "adminCode": "610100"  
    }  
  ]  
}';
        $cate = "_10_";
        $carType="moto";
        $course="kemu3";
        $label="k4";

        $sf=json_decode($json,1);
        foreach ($sf["provinces"] as $s)
        {
            $sign=$this->getRequest("http://sv.daimapuzi.com/api/whale/sign1");
            $url="https://api2.jiakaobaodian.com/api/open/chapter/list.htm?_r=".$sign."&carType=".$carType."&course=".$course."&cityCode=".$s["adminCode"];
            $return = json_decode($this->getRequest($url),1);
            foreach ($return["data"] as $list)
            {
                if(strpos($list["title"],"地方")){
                    Db::table("zl_questions_chapter")->insert([
                        "source_id"=>$list["id"],
                        "name"=>$list["title"],
                        "cate"=>$cate,
                        "label"=>$label,
                        "is_show"=>20,
                        "code"=>$s["name"],
                    ]);
                    var_dump($s["name"]);
                }
            }

            //Db::table("zl_questions_chapter")->where("id",$chapter["id"])->update(["ids"=>json_encode($return["data"]["questionList"])]);
        }



        //https://api2.jiakaobaodian.com/api/open/exercise/chapter.htm?_r=15865934284311697097&carStyle=xiaoche&carType=car&chapterId=271&cityCode=110000&course=kemu3&kemuStyle=kemu4&tagId=270&_=0.9622149806541889
    }

    //地方题库ids
    public function difangId(){

        $chapters=Db::table("zl_questions_chapter")
            ->where("sort","0")
            ->select();
        foreach ($chapters as $chapter)
        {
            $ids=json_decode($chapter["ids"],1);
            $data=[];
            foreach ($ids as $id)
            {
                $data[]=[
                    "source_id"=>$id,
                    "cate"=>$chapter["cate"],
                    "label"=>$chapter["label"],
                    "source"=>"jkbd",
                    "label3"=>$chapter["code"],
                ];
            }
            Db::table("zl_questions_content")->insertAll($data);

        }
    }

    //详情
    public function difangDetail()
    {

        $carStyle=[
            "_7_"=>"xiaoche",
            "_8_"=>"keche",
            "_9_"=>"huoche",
            "_10_"=>"moto",
            "_12_"=>"keyun",
            "_13_"=>"huoyun",
            "_14_"=>"weixian",
            "_15_"=>"jiaolian",
            "_16_"=>"chuzu",
            "_17_"=>"light_trailer",
            "_18_"=>"wangyue",
            "_20_"=>"chache",
            "_19_"=>"weixian_yayun",
            "_21_"=>"weixian_zhuangxie",
        ];

        $carType=[
            "_7_"=>"car",
            "_8_"=>"bus",
            "_9_"=>"truck",
            "_10_"=>"moto",
            "_12_"=>"keyun",
            "_13_"=>"huoyun",
            "_14_"=>"weixian",
            "_15_"=>"jiaolian",
            "_16_"=>"chuzu",
            "_17_"=>"light_trailer",
            "_18_"=>"wangyue",
            "_20_"=>"chache",
            "_19_"=>"weixian_yayun",
            "_21_"=>"weixian_zhuangxie",
        ];


        set_time_limit(0);
        $list=Db::table("zl_questions_content")
            ->where("id","<=",25798)
            ->where("id",">=",25760)
            ->order("id","desc")
            ->select();

        $optionType=[
            0=>20,
            1=>10,
            2=>10
        ];

        $optionTypeC=[
            0=>10,
            1=>10,
            2=>20
        ];
        foreach ($list as $item)
        {
            $id=$item["source_id"];
            $content=json_decode($this->view($carType[$item["cate"]],$id),1);
            $question=[
                "question"=>$content["data"]["question"],
                "key_words"=>$content["data"]["assuredKeywords"],
                "answer"=>$content["data"]["answer"],
                "media_url"=>$content["data"]["mediaContent"],
                "media_type"=>$content["data"]["mediaType"]."0",
                "item1"=>$content["data"]["optionA"],
                "item2"=>$content["data"]["optionB"],
                "item3"=>$content["data"]["optionC"],
                "item4"=>$content["data"]["optionD"],
                "item5"=>$content["data"]["optionE"],
                "item6"=>$content["data"]["optionF"],
                "item7"=>$content["data"]["optionG"],
                "item8"=>$content["data"]["optionH"],
                "concise_explains"=>$content["data"]["conciseExplain"],
                "difficulty"=>$content["data"]["difficulty"],
                "wrong_rate"=>$content["data"]["wrongRate"],
                "ext"=>$content["data"]["label"], //标签
                "ext1"=>$content["data"]["chapterId"], //专题
                "explains"=>$content["data"]["explain"],
                "type"=>$optionType[$content["data"]["optionType"]],
                "type_c"=>$optionTypeC[$content["data"]["optionType"]],
            ];
            Db::table("zl_questions_content")->where("source_id",$id)->update($question);
            exit;
        }



        return 1;

    }


    //图片标志
    public function imagesGroup()
    {
        $sign=$this->getRequest("http://sv.daimapuzi.com/api/whale/sign1");
        $url="https://panda.kakamobi.cn/api/web/traffic-icon/group-list.htm?_r=".$sign;
        $list=json_decode($this->getRequest($url),1);
        $groups=[];
        foreach ($list["data"]["itemList"] as $group)
        {
            $groups[]=[
                "source_id"=>$group["id"],
                "group_name"=>$group["name"],
                "count"=>$group["count"],
                "images"=>json_encode($group["imageList"],302),
                "ids"=>json_encode($group["iconIdList"],302),
            ];
        }
  
        Db::table("zl_questions_image_grop")->insertAll($groups);


    }

    public function images()
    {
        $groups=Db::table("zl_questions_image_grop")->where("id","<=",10000)->select();
        foreach ($groups as $group)
        {
            $sign=$this->getRequest("http://sv.daimapuzi.com/api/whale/sign1");
            $url="https://panda.kakamobi.cn/api/web/traffic-icon/icon-list.htm?_r=".$sign."&groupId=".$group["source_id"];
            $list=json_decode($this->getRequest($url),1);
            $groups=[];
            foreach ($list["data"]["itemList"] as $image)
            {
                $groups[]=[
                    "source_id"=>$image["id"],
                    "group_id"=>$image["groupId"],
                    "title"=>$image["title"],
                    "content"=>$image["content"],
                    "image_url"=>$image["imageUrl"],
                ];
            }
            Db::table("zl_questions_image")->insertAll($groups);
        }


    }

    public function imagesForQes()
    {
        $groups=Db::table("zl_questions_image_grop")->where("id","<=",10000)->select();
        foreach ($groups as $group)
        {
            $sign=$this->getRequest("http://sv.daimapuzi.com/api/whale/sign1");
            $url="https://panda.kakamobi.cn/api/web/traffic-icon/icon-list.htm?_r=".$sign."&groupId=".$group["source_id"];
            $list=json_decode($this->getRequest($url),1);

            foreach ($list["data"]["itemList"] as $image)
            {

                $zl_questions_image=Db::table("zl_questions_image")->where("source_id",$image["id"])->find();

                if($image["ke1QuestionList"]){
                    Db::table("zl_question_attach")->where("q_s_id","in",implode(",",$image["ke1QuestionList"]))->update(["n_url"=>$zl_questions_image["image_url"],"status"=>20]);
                }
                if($image["ke4QuestionList"])
                {
                    Db::table("zl_question_attach")->where("q_s_id","in",implode(",",$image["ke4QuestionList"]) )->update(["n_url"=>$zl_questions_image["image_url"],"status"=>20]);
                }

            }

        }


    }

    public function imagesUpdate()
    {
        $groups=Db::table("zl_questions_image_grop")->where("id","<=",10000)->select();
        foreach ($groups as $group)
        {

            Db::table("zl_questions_image")->where("group_id",$group["source_id"])->update(["group_id"=>$group["id"]]);
//            var_dump(Db::table("zl_questions_image")->getLastSql());
//                        var_dump($group);exit;
        }
    }

    public function sign1()
    {
        $content='
            var r =function(t) {
                var e, n, a = Math.abs(parseInt((new Date).getTime() * Math.random() * 1e4)).toString(), o = 0;
                for (e = 0; e < a.length; e++)
                    o += parseInt(a[e]);
                return n = function(t) {
                    return function(e, n) {
                        return n - "" + e.length <= 0 ? e : (t[n] || (t[n] = Array(n + 1).join(0))) + e
                    }
                }([]),
                o += a.length,
                o = n(o, 3 - o.toString().length),
                t.toString() + a + o
            }
            console.log(r(1));
    ';
        $res = exec('node -e "' . $content . '"');

        return $res;

    }

    //精简500题
    public function jj()
    {
        $carType=[
            "_7_"=>"car",
            "_8_"=>"bus",
            "_9_"=>"truck",
            "_10_"=>"moto",
            "_12_"=>"keyun",
            "_13_"=>"huoyun",
            "_14_"=>"weixian",
            "_15_"=>"jiaolian",
            "_16_"=>"chuzu",
            "_17_"=>"light_trailer",
            "_18_"=>"wangyue",
            "_19_"=>"weixian_yayun",
            "_20_"=>"chache",
            "_21_"=>"weixian_zhuangxie",
        ];

        $carType="weixian_zhuangxie";
        $type11="_21_";
        $course="zigezheng";
        $label="zigezheng";
        $sign=$this->getRequest("http://sv.daimapuzi.com/api/whale/sign1");
        $url="https://api2.jiakaobaodian.com/api/open/question/top-rate-500.htm?carType=".$carType."&course=".$course."&_r=".$sign;
        $lists=json_decode($this->getRequest($url),1);
        $data=[];
        foreach ($lists["data"] as $list)
        {
            $data[]=[
                "source_id"=>$list,
                "cate"=>$type11,
                "label"=>$label,
                "source"=>"jkbd",
                "is_vip"=>20,
                "ext2"=>500,
            ];
        }
        Db::table("zl_questions_content")->insertAll($data);
        var_dump($lists["data"]);exit;
    }

    //精简500题
    public function jjDetail()
    {
        set_time_limit(0);
        $list=Db::table("zl_questions_content")
            ->where("id","<=",26627)
            ->order("id","desc")
            ->select();

        $optionType=[
            0=>20,
            1=>10,
            2=>10
        ];

        $optionTypeC=[
            0=>10,
            1=>10,
            2=>20
        ];

        $carType=[
            "_7_"=>"car",
            "_8_"=>"bus",
            "_9_"=>"truck",
            "_10_"=>"moto",
            "_12_"=>"keyun",
            "_13_"=>"huoyun",
            "_14_"=>"weixian",
            "_15_"=>"jiaolian",
            "_16_"=>"chuzu",
            "_17_"=>"light_trailer",
            "_18_"=>"wangyue",
            "_19_"=>"weixian_yayun",
            "_20_"=>"chache",
            "_21_"=>"weixian_zhuangxie",
        ];

        foreach ($list as $item)
        {
            $id=$item["source_id"];
            $content=json_decode($this->view($carType[$item["cate"]],$id),1);
            $question=[
                "illiteracy_explain"=>$content["data"]["illiteracyExplain"],
                "illiteracy_keywords"=>$content["data"]["illiteracyKeywords"],
            ];
            Db::table("zl_questions_content")->where("source_id",$id)->update($question);
        }



        return 1;


    }

    public function downImage()
    {

        set_time_limit(0);
        $images=Db::table("zl_question_attach")
            ->distinct("s_url")
            ->where("id",">=",1)
            ->where("type",10)
            ->where("status",10)
            ->group("s_url")
            ->select()->toArray();
        foreach ($images as $image)
        {
            $resource=file_get_contents($image["s_url"]);
            file_put_contents("../public/static/quesimg/".$image["q_id"].".jpg",$resource);
        }
    }

    public function updateImage()
    {
        set_time_limit(0);
        $images=Db::table("zl_questions_image")->where("id",">=",1)->select();
        foreach ($images as $image)
        {

            Db::table("zl_questions_image")->where("id",$image["id"])->update([
                "image_url"=>"http://image.daimapuzi.com/jzjk_iocn/".$image["id"].".jpg"
            ]);

        }
    }

    public function collectImage()
    {
        $qestions=Db::table("zl_questions_content")->where("media_type","=",10)->select();
        $data=[];
        foreach ($qestions as $qestion)
        {
            $data[]=[
                "s_url"=>$qestion["media_url"],
                "q_id"=>$qestion["id"],
                "q_s_id"=>$qestion["source_id"],
                "type"=>$qestion["media_type"],
            ];
        }
        Db::table("zl_question_attach")->insertAll($data);


    }



    public function getRequest($url)
    {
        $curl = curl_init();
        curl_setopt($curl, CURLOPT_URL, $url);
        // curl_setopt($curl, CURLOPT_TIMEOUT, 10);
        // curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 10);
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
        $output = curl_exec($curl);
        curl_close($curl);
        return $output;
    }


}